﻿using QFramework;
using UnityEngine;

namespace SnakeGame
{
    public class CreateFoodCommand : AbstractCommand
    {
        private readonly int mapW, mapH;

        public CreateFoodCommand(int w, int h)
        {
            mapW = w;
            mapH = h;
        }
        protected override void OnExecute()
        {
            Node node;
            var map = this.GetSystem<IGridMapSystem>();
            do node = map.GetNode(Random.Range(1, mapW - 1), Random.Range(1, mapH - 1));
            while (node.State != Node.E_State.Blank);
            map.SetNodeState(node, Node.E_State.Food);
        }
    }
}